/** 电神魔傀2,没有A下上因为可以用模拟器的宏统一代替

  By setycyas @2024-10-29
*/

/* 全局设定
*/ {
#Warn
#MaxThreadsPerHotkey 1
SetWorkingDir(A_ScriptDir)
#Include "..\Class\FaceDetector.2.ahk"
#Include "..\Class\CommonMacro.2.ahk"
#Include "..\Class\CommonUI.2.ahk"
#Include "..\Class\MyFuns.2.ahk"
#Include "..\Class\MyEmu.2.ahk"
#Include "..\Class\OrderMap.2.ahk"
;SendMode("Event")
SendMode("Input")
}

/* 制作电神魔傀2专用的宏类
*/ class DM2Macro extends CommonMacro {

  UI := "" ;显示需要的ui

  /* 构造函数,设定预设数据
  */
  __New(faceDetector, keys){
    super.__New(faceDetector, keys)
  }
  
  /* 函数 
  */
  
  /* 新增的宏函数
  */
  _A上下前(key){
    local face := this._face.face()
    this._down(1)
    sleep(40)
    MyFuns.press("up", 20)
    sleep(50)
    MyFuns.press("down", 20)
    sleep(50)
    MyFuns.press(face, 20)
    sleep(30)
    this._up(1)
  }
  _A下下(key){
    this._down(1)
    sleep(40) ;测试发现这里至少40
    MyFuns.press("down", 20)
    sleep(30)
    MyFuns.press("down", 20)
    sleep(30)
    this._up(1)
  }
  _A后前(key){ ;黑骑士超必杀需要冲跑按此键后继续按住方向键
    local face := this._face.face()
    local back := this._face.back()
    this._down(1)
    sleep(40)
    MyFuns.press(back, 20)
    sleep(30)
    MyFuns.press(face, 20)
    sleep(30)
    this._up(1)
  }
  _A下前(key){
    local face := this._face.face()
    this._down(1)
    sleep(40)
    MyFuns.press("down", 20)
    sleep(30)
    MyFuns.press(face, 20)
    sleep(30)
    this._up(1)
  }
  _A前前后前(key){ ;手搓失败往往是按下a后没等40毫秒就搓,系统还没有搓招判定
    local face := this._face.face()
    local back := this._face.back()
    this._down(1)
    sleep(40)
    MyFuns.press(face, 20)
    sleep(50)
    MyFuns.press(face, 20)
    sleep(50)
    MyFuns.press(back, 20)
    sleep(50)
    MyFuns.press(face, 20)
    sleep(50)
    this._up(1)
  }
  
  /* 重载宏接口
  */
  _setMacro(){
    static obm := ObjBindMethod
    static m := OrderMap() ;this.macroMap的缩短版
    this.macroMap := m
    m["A上下前"] := obm(this, "_A上下前")
    m["A下下"] := obm(this, "_A下下")
    m["A后前"] := obm(this, "_A后前")
    m["A下前"] := obm(this, "_A下前")
    m["A前前后前"] := obm(this, "_A前前后前")
    m["空函数"] := obm(this, "_空函数")
    this.macroArr := m.getKeys()
  }
}

/* 制作电神魔傀2专用UI
*/
class DM2UI extends CommonUI {

  EXE_ARRAY := [MyEmu.MAME, MyEmu.XZONE]

  /* 构造函数
  */
  __New(macro){
    super.__New("电神魔傀2", macro)
    this._preset := OrderMap([
      "眼镜", ["A上下前", "A下下"],
      "黑骑士", ["A后前", "A下下"],
      "刃零", ["A前前后前", "A后前"],
      "虫子", ["A前前后前", "A下下"],
      "胧天明", ["A后前", "A后前"],
      "天使", ["A上下前", "A后前"],
      "肌肉男", ["A下前", "A后前"],
      "机器人", ["A后前", "A后前"]
    ])
    this._macro.UI := this ;绑定UI
  }

  /* 重写接口
  */

  /* 重写setup,更改可选的exe,读入预设
  */
  setup(){
    super.setup()
    this._myGui.opt("+AlwaysOnTop")
    this._myGui.show("x1100 y330")
    this.readPresetMenu("眼镜")
  }

}

/* 运行当前脚本
*/ if (A_ScriptName == "电神魔傀2.2.ahk") {
  face := FaceDetector() ;方向检测对象
  macro := DM2Macro(face, ["w","e"]) ;宏对象,有界面时第二个参数可以随便写但长度不要小于2
  ;新建界面对象并显示
  ui := DM2UI(macro)
  ui.setup()
  ;更新组件内容
  ui._exeComboBox.Choose(MyEmu.MAME)
  ;ui._exeComboBox.Choose(MyEmu.XZONE)
  ui._gameKeyEdit.Text := "a,d,x" 
  ui._hotkeyEdit.Text := "~e,~f"
  ui._fpsEdit.Text := "20"
  ui._testEdit.Text := "30,80,80,2100"
  ui.readPresetMenu("眼镜")
}
